<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<link rel="stylesheet" type="text/css" href="/easyui/demo.css">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<body class="easyui-layout">
<!-- 说明 字符串：Project，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
	<!-- 主表  -->
	<table id="project_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/project-list/0/1/20',
					  method:'get',
					  toolbar:'#tb',
					  loadMsg : '数据加载中',
					  onDblClickRow:onDblClickRow,
					  onRowContextMenu: onRowContextMenu,
					  onLoadSuccess:function(data){
                            $('.ok').linkbutton({plain:true,iconCls:'icon-ok'});
                            $('.uuid').linkbutton({plain:true,iconCls:'icon-new'});
                    },
					  showFooter: true" >
        <thead frozen="true">
            <tr>
                <th data-options="field:'proRukuFlag',width:40,align:'center',formatter:info "></th>
                <th data-options="field:'uuid',width:40,align:'center',formatter:uuidfile"></th>
                <th data-options="field:'proName',width:200,align:'center' ">项目名称</th>
                <#--<th data-options="field:'proCategory',width:100,align:'center' ,formatter:proCategoryFormatter ">项目分类</th>-->
            </tr>
        </thead>
        <thead>
            <tr>
                <#--<th data-options="field:'proId',width:250,align:'center' ">项目编号</th>-->
                <th data-options="field:'proCompanyCondition',width:300,align:'center'  ">公司情况</th>
                <th data-options="field:'proCompanyRequire',width:300,align:'center' ">公司需求</th>
                <th data-options="field:'proLabel',width:250,align:'center' ">项目进度</th>
                <th data-options="field:'userId',width:100,align:'center' ,formatter:userIdFormatter">业务人员</th>
            </tr>
        </thead>
	</table>
</div>

<!-- 操作栏 -->
<div id="tb" style="padding:5px;height:auto">
    <div>

        项目名称:
        <input class="easyui-textbox" name="proName"id="proName">
        项目分类:
        <input class="easyui-combobox" name="proCategory"id="proCategory"
               data-options="
				url : '/constants/proj_category',
				method: 'get',
				valueField:'key',
				textField:'value',
        ">
        项目编号:
        <input class="easyui-textbox" name="proId"id="proId">
        <#--业务人员:-->
        <#--<input class="easyui-textbox" name="proManager"id="proManager">-->
        <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
    </div>
    <div style="margin-top: 5px">
        <#include "/common/button.html">
    </div>
</div>

<!-- 右键 -->
<div id="right_click" class="easyui-menu" style="width:120px;">
    <div onclick="nx()" data-options="iconCls:'icon-add'">立项</div>
    <div class="menu-sep"></div>
    <div onclick="de()" data-options="iconCls:'icon-remove'">删除</div>
    <div onclick="yc('Y')" data-options="iconCls:'icon-cancel'">否决</div>
    <div onclick="ed()" data-options="iconCls:'icon-edit'">编辑</div>
    <div onclick="query()" data-options="iconCls:'icon-add'">查看</div>
    <div onclick="up()" data-options="iconCls:'icon-upload'">上传</div>
    <div onclick="projectExport()" data-options="iconCls:'icon-upload'">导出</div>
</div>




<script type="text/javascript">
    function info(value,row) {
        var button = '';
        if(value==1){
            button += '<a href="#" class="ok" title="信息已经完善"></a>';
        }
        return button;
    }
    function uuidfile(value){
        var result = '';
        $.ajax({
            url : '/project-has-file/'+value+'/RK',
            async : false,
            success :function (data) {
                result = data;
            }
        })
        var button = '';
        if(result){
            button += '<a href="#" class="uuid" title="文件已经上传" onclick="uidFile(\''+value+'\')"></a>';
        }
        return button;
    }
    function uidFile(value){
        var url = '/project-files-show/'+value+'/RK';
        var index = layer.open({
            title: false,
            type: 2,
            area: ['900px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
     }
    function  proCategoryFormatter(val) {
        var result = '';
        $.ajax({
            url : '/constants/proj_category/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }
    function userIdFormatter(val){
        var result = '';
        $.ajax({
            url : '/user-get/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }

</script>

<!-- 按钮操作 -->
<script type="text/javascript">
    //新增
    $("#add").click(function () {
        var url = '/project-add';
        var index = layer.open({
            title:'项目入库',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
        layer.full(index);
    })


    function yc(val){
        var ycOrVeto = '';
        if(val == 'N'){
            ycOrVeto = '此项目被标记为异常，请描述异常原因';
        }else {
            ycOrVeto = '此项目被否决，请描述否决原因';
        }
        layer.prompt({title: ycOrVeto, formType: 2}, function(text, index){
            layer.close(index);
            var node = $('#project_table').datagrid('getSelected');
            $.ajax({
                type :'post',
                url : '/errorproject-set/'+val+'/'+node.id+'/',
                data : {reason:text,state:'入库阶段'},
                async :false,
                success :function(){
                    var handler = '/project-list/0/1/20';
                    $('#project_table').datagrid('options').url = handler;
                    $('#project_table').datagrid('reload');
                }
            });
        });
    }
    //上传结束
	$('#export').click(function(){
        window.location = "/project-download/0";
    });
    //数据导入
    $('#upload').click(function () {
        var url = '/project-ruku-upload';
        var index = layer.open({
            title:'项目信息导入',
            type: 2,
            area: ['780px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
        layer.full(index);
    });


    function projectExport() {
        var node = $('#project_table').datagrid('getSelected');
        if(null != node && "" != node){
            var id = node.id;
            var url = '/projectInfo-validate/'+id;
            var index = layer.open({
                title:'项目明细',
                type: 2,
                area: ['700px', '450px'],
                fixed: true, //不固定
                maxmin: true,
                content: url
            });
            layer.full(index);
        }else {
            layer.msg("请选择数据！");
        }
    }
</script>

<!--条件查询 -->
<script>
    $("#searchByParameter").click(function(){
        var proName = $("#proName").val();
        var proCategory = $("#proCategory").val();
        var proId = $("#proId").val();
        var handler = '/project-list/0/1/20?proName='+proName+"&proCategory="+proCategory+"&proId="+proId;
        $('#project_table').datagrid('options').url = handler;
        $('#project_table').datagrid('reload');
    });
</script>
<!-- 分页-->
<script type="text/javascript">
	$(function(){
		var p = $('#project_table').datagrid().datagrid('getPager');
		p.pagination({
			pageSize: 20, //每页显示的记录条数，默认为10
			pageList: [20, 40, 60], //可以设置每页记录条数的列表
			onSelectPage: function (pageNumber, pageSize) {
			    if(pageNumber==0){
			        pageNumber = 1;
                }
                var proName = $("#proName").val();
                var proCategory = $("#proCategory").val();
                var proId = $("#proId").val();
				var handler = '/project-list/0/'+pageNumber+"/"+pageSize+"?proName="+proName+"&proCategory="+proCategory+"&proId="+proId;
				$('#project_table').datagrid('options').url = handler;
				$('#project_table').datagrid('reload');
			}
		});
	})
</script>

<!-- 右键操作 -->
<script>
    function onRowContextMenu(e,row){
        e.preventDefault();
        var node = $('#project_table').datagrid('getSelected');
        if(node){
            $('#right_click').menu('show',{
                left: e.pageX,
                top: e.pageY
            });
        }
    }
    function onDblClickRow(rowIndex,rowData){
        var id = rowData.id;
        var title = rowData.proName;
        var url = '/project-ruku-view/'+id;
        var index = layer.open({
            type: 2,
            title:title,
            area: ['420px', '240px'], //宽高
            closeBtn: 1, //不显示关闭按钮
            anim: 2,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            content: url
        });
        layer.full(index);

    }

    function nx(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var url = '/project-ruku-validate/'+id+'/0';
        var index = layer.open({
            title:'项目入库信息明细',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
        layer.full(index);

    }
    function de(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        url = '/project-ins-upd-del/'+id;
        $.messager.confirm('删除信息','确定删除此项目?',function(r){
            if (r){
                $.post(url,{deleteFlag:'Y',tm:new Date()},function(result){
                    $('#project_table').datagrid('reload');    // reload the user data
                });
            }
        });
    }
    function ed(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var url = '/project-ruku-edit/'+id+'/0';
        var index = layer.open({
            title:'项目修改',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
        layer.full(index);
    }
    function query() {
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var title = node.proName;
        var url = '/project-ruku-view/'+id;
        var index = layer.open({
            type: 2,
            title:title,
            area: ['420px', '240px'], //宽高
            closeBtn: 1, //不显示关闭按钮
            anim: 2,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            content: url
        });
        layer.full(index);
    }
    function up(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var url = '/common-upload/'+id+'/0';
        var index = layer.open({
            title:'资料上传',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            end:function () {
                var handler = '/project-list/0/1/20';
                $('#project_table').datagrid('options').url = handler;
                $('#project_table').datagrid('reload');
            },
            content: url
        });
        layer.full(index);
    }
</script>